﻿Imports System.Data
Imports System.IO
Imports amod2
Imports formulare

Public Class Main


#Region "private attributes"


    Private aSettingsPathForDBGen As String     ' cesta kde sa ulozi fyzicka databaza /dano
    Dim aPathKroslibProject As String       ' cesta k vbproj suboru kroslibu    
    Dim aPathKroslibProjectFile As String
    Dim aSolutionWorker As SourceCode_worker         'ostane objekt na vytvaranie solution
    Dim aDbGen As New DBGen()                        'ostane objekt na vytvaranie databazy
    Dim aFrmGen As GeneratorFormularov               'ostane objekt na vytvaranie formularom
    Dim aModulesDict As Dictionary(Of String, String)   'meno modulu + cesta k prislusnemu amodu
    Dim aPathRootTemplate As String                     ' cesta ku root adresaru s templatmi
    Dim aDbGenSettings As DBGenSettings                 ' objekt nastaveni generatora databazi
    Dim aPathDestination As String                      ' cielovy adresar kam sa vygeneruje projekt
    Dim aProjectName As String                         ' nazov solution
    Dim aSolutionName As String
    Dim aFileNames As New Files()                             ' nazvi suborov a templatov
    Dim aExportSettings As New ExportSettings()               ' setting na generovanie formularov


#End Region

    ''' <summary>
    ''' konstruktor Main
    ''' </summary>
    ''' <param name="pModulesFolderName">???</param>
    ''' <param name="pProjectFolderName">???</param>
    ''' <param name="pPathRootTemplate">Cesta ku korenovskemu adresaru s Templatmi</param>
    ''' <param name="pDbGenSettings">Nastavenia DB Generatora</param>
    ''' <param name="pPathDestination">Cielova cesta kde sa vytvori Novy Projekt</param>
    ''' <param name="pProjectName">Nazov adresara v ktorom bude Novy Projekt</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal pModulesFolderName As String, ByVal pProjectFolderName As String, ByVal pPathRootTemplate As String, ByVal pDbGenSettings As DBGenSettings, ByVal pPathDestination As String, ByVal pProjectName As String)
        ' Me.aFileNames.mFolderBaseProject = pProjectFolderName
        Me.aFileNames.mFolderModules = pModulesFolderName
        Me.aPathDestination = pPathDestination
        Me.aDbGenSettings = pDbGenSettings
        Me.aPathRootTemplate = pPathRootTemplate
        Me.aProjectName = pProjectName
        Me.aSolutionName = pProjectName
        Me.aSolutionWorker = New SourceCode_worker(Me.aFileNames, pPathRootTemplate, pPathDestination, pProjectName)
    End Sub
    ''' <summary>
    ''' konstruktor
    ''' </summary>
    ''' <param name="pPathRootTemplate">Root adresar k templatom</param>
    ''' <param name="pDbGenSettings">Nastavenie DB Generatora</param>
    ''' <param name="pPathDestination">Root adresar kde sa vytvorit Novy Solution(v tomto Root adresary sa nachadza aj Amod Solution subor)</param>
    ''' <param name="pProjectName">Nazov vysledneho Solution(takto sa bude volat subor SLN) a takto by sa mal volat adresar v ktorom su podadresare s modulmi</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal pPathRootTemplate As String, ByVal pDbGenSettings As DBGenSettings, ByVal pPathDestination As String, ByVal pProjectName As String)
        Me.aPathDestination = pPathDestination
        Me.aDbGenSettings = pDbGenSettings
        Me.aPathRootTemplate = pPathRootTemplate
        Me.aProjectName = pProjectName
        Me.aSolutionName = pProjectName
        Me.aSolutionWorker = New SourceCode_worker(Me.aFileNames, pPathRootTemplate, pPathDestination, pProjectName)
    End Sub




#Region "Private methods"
    ''' <summary>
    ''' vtati kod pre init component cast
    ''' </summary>
    ''' <param name="pName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetComponentInitsCode(ByVal pName As String) As String
        Return "Me." & pName & " = New System.Windows.Forms.Button" & vbCrLf
    End Function
    ''' <summary>
    ''' vtati kod pre setting component cast
    ''' </summary>
    ''' <param name="pName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetComponenttSettingsCode(ByVal pName As String, ByVal x As Integer, ByVal y As Integer) As String
        Return "'" & pName & "'" & vbCrLf & _
                      "Me." & pName & ".Location = New System.Drawing.Point(" & x & ", " & y & ")" & vbCrLf & _
                      "Me." & pName & ".Name = """ & pName & """" & vbCrLf & _
                      "Me." & pName & ".Size = New System.Drawing.Size(220, 23)" & vbCrLf & _
                      "Me." & pName & ".TabIndex = 0" & vbCrLf & _
                      "Me." & pName & ".Text = """ & pName & """" & vbCrLf & _
                      "Me." & pName & ".UseVisualStyleBackColor = True" & vbCrLf
    End Function
    ''' <summary>
    ''' vrati kod pre unit registraciu pohladoveho formularu
    ''' </summary>
    ''' <param name="pModul"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function getUnitRegVw(ByVal pModul As String)
        Dim lUnitsPart As String
        lUnitsPart = vbCrLf & vbCrLf & "' List_View_" & pModul
        lUnitsPart = lUnitsPart & vbCrLf & "u = New Unit(""List_" & pModul & """)"
        lUnitsPart = lUnitsPart & vbCrLf & "u.AddFrm(GetType(" & Me.aFileNames.mPrefixFrm & pModul & "), ""VIEW_" & pModul & """)"
        lUnitsPart = lUnitsPart & vbCrLf & "u.AddTables(""VIEW_" & pModul & """)"
        lUnitsPart = lUnitsPart & vbCrLf & "Me.AddListUnit(u)"
        Return lUnitsPart
    End Function
    ''' <summary>
    ''' vrati kod pre unit registraciu formularov
    ''' </summary>
    ''' <param name="pUnits"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function getUnitReg(ByVal pUnits As List(Of String))
        Dim lUnitsPart As String
        For Each lUnitName As String In pUnits
            lUnitsPart = lUnitsPart & vbCrLf & vbCrLf & "'" & lUnitName
            lUnitsPart = lUnitsPart & vbCrLf & "u = New Unit(""" & lUnitName & """)"
            lUnitsPart = lUnitsPart & vbCrLf & "u.AddFrm(GetType(" & Me.aFileNames.mPrefixFrm & lUnitName & "), """ & Me.aFileNames.mPrefixFrm & lUnitName & """)"
            lUnitsPart = lUnitsPart & vbCrLf & "u.AddLog(GetType(" & Me.aFileNames.mPrefixLog & lUnitName & "), """ & Me.aFileNames.mPrefixLog & lUnitName & """)"
            lUnitsPart = lUnitsPart & vbCrLf & "u.AddTables(""" & lUnitName & """)"
            lUnitsPart = lUnitsPart & vbCrLf & "Me.AddUnit(u)"
        Next
        Return lUnitsPart
    End Function


    ''' <summary>
    ''' vtati kod pre add component cast
    ''' </summary>
    ''' <param name="pName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetComponentAddsCode(ByVal pName As String) As String
        Return "Me.Controls.Add(Me." & pName & ")" & vbCrLf
    End Function
    ''' <summary>
    ''' vtati kod pre friend component cast
    ''' </summary>
    ''' <param name="pName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetComponentFriendsCode(ByVal pName As String) As String
        Return "Friend WithEvents " & pName & " As System.Windows.Forms.Button" & vbCrLf
    End Function
    ''' <summary>
    ''' vtati kod pre click component cast
    ''' </summary>
    ''' <param name="pName"></param>
    ''' <param name="pUnitName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetComponentClicksCode(ByVal pName As String, ByVal pUnitName As String) As String
        Return "Private Sub " & pName & "_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles " & pName & ".Click" & vbCrLf & _
                    "Dim frm As New frm_" & pUnitName & "()" & vbCrLf & _
                    "frm.ShowDialog()" & vbCrLf & _
                    "End Sub" & vbCrLf
    End Function

    Private Sub GenerateOneFormular(ByVal pModul As String, ByVal pModulPath As String, ByVal pUnit As String, ByVal overwrite As Boolean)

        Dim aDat As Dat
        Dim aOneDataset As DsAModOneVersion ' dataset jednej verzie z ktoreho sa bude generovat databaza
        Dim aVersion As String

        ' nacitat settings pre DB Generator
        Dim aDlgDBGen As New DlgDBGenerator()
        If (Me.DBGeneratorSettings IsNot Nothing) Then    ' ak eksistuje uz nastavenie
            aDlgDBGen.SetComponents(Me.DBGeneratorSettings)
        End If
        aDlgDBGen.giveData(Me) ' prerobit na konstruktor a aby vracal denSettings ako navrat hodnotu
        aDlgDBGen.ShowDialog()

        aDat = New Dat("NazovModuluDano", "NazovModulu", "NazovModulu")
        ' 3 krok - pridanie formularov do adresarov modulov v novom projekte
        Dim aPathTemplateComponents As String = Me.aPathRootTemplate & "\" & Me.aFileNames.mFolderFormTemplates & "\" & Me.aFileNames.mFileFormComponents
        aDat.LoadDsComponents(aPathTemplateComponents)

        Me.aFrmGen = New GeneratorFormularov(Path.Combine(Me.aPathRootTemplate, Me.aFileNames.mFolderFormTemplates), aDat)
        aDat.LoadAMod(pModulPath, "CHYBA - Nepodarilo sa otvoriť Amod súbor pri generovaní databázy.")
        ' nastavi sa verzia a nacita konkretny dataset podla verzie
        If (Me.aDbGenSettings.Ver = -1) Then
            aVersion = aDat.GetLastVersion.ToString()
            aOneDataset = aDat.GetVersionDataset(aVersion) 'ak ide o poslednu verziu
        Else
            aVersion = Me.aDbGenSettings.Ver
            aOneDataset = aDat.GetVersionDataset(aVersion)
        End If
        For Each aDataRow As DataRow In aOneDataset.Tables(aOneDataset.UnitsTable.TableName).Rows
            Dim aUnitName As String = (aDataRow("UnitName"))  'dano
            'aUnits.Add(aUnitName)

            If (aUnitName = pUnit) Then
                Dim aFrmFormulareExport As FrmFormulareExport = New FrmFormulareExport(Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFolderModules & "\" & pModul, aUnitName, aFrmGen, aExportSettings, aDat.GetLastVersion, "Zoznamovy Form")
                aFrmFormulareExport.ShowDialog()

                ' zmenim referencie na
                If (overwrite = False) Then

                    Dim lComponentsInit As String
                    Dim lComponentsSetting As String
                    Dim lComponentsAdd As String
                    Dim lComponentsFriend As String
                    Dim lComponentClickCode As String

                    Dim aOtherFiles As New List(Of String)()
                    Dim aResxFiles As New Dictionary(Of String, String)
                    Dim aVBFiles As New List(Of String)()

                    Dim lName As String = pModul & "_" & aUnitName
                    lComponentsInit += Me.GetComponentInitsCode(lName)
                    Dim y As Integer
                    Dim rnd As New Random
                    y = rnd.Next(0, 270)
                    lComponentsSetting += Me.GetComponenttSettingsCode(lName, 50, y)

                    lComponentsAdd += Me.GetComponentAddsCode(lName)

                    lComponentsFriend += Me.GetComponentFriendsCode(lName)

                    lComponentClickCode += Me.GetComponentClicksCode(lName, aUnitName)

                    aResxFiles.Add(aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionVBSource, aFileNames.mFolderModules & "\" & pModul & "\" & aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionResx)
                    aVBFiles.Add(aFileNames.mFolderModules & "\" & pModul & "\" & aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionVBSource)
                    aVBFiles.Add(aFileNames.mFolderModules & "\" & pModul & "\" & aFileNames.mPrefixLog & aUnitName & aFileNames.mExtensionVBSource)



                    Me.aSolutionWorker.updateMainForm(Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFileTplFrmMain, Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFileTplFrmMainDesigner, lComponentsInit, lComponentsSetting, lComponentsAdd, lComponentsFriend, lComponentClickCode)
                    Me.aSolutionWorker.updateProjectFile(aPathDestination & "\" & aProjectName, aOtherFiles, aResxFiles, aVBFiles)
                End If
            End If
        Next
    End Sub
#End Region

#Region "property"
    Public Property DBGenerator() As DBGen
        Get
            Return aDbGen
        End Get
        Set(ByVal Value As DBGen)
            aDbGen = Value
        End Set
    End Property
    Public Property DBGeneratorSettings() As DBGenSettings
        Get
            Return aDbGenSettings
        End Get
        Set(ByVal Value As DBGenSettings)
            aDbGenSettings = Value
        End Set
    End Property
#End Region

#Region "Generate Project with only one Form which referenced on existing Form in Complete Project"
    ''' <summary>
    ''' generovanie jedneho formularov z jedneho unitu
    ''' </summary>
    ''' <param name="pModul">nazov modulu z ktoreho sa ide generovat formular</param>
    ''' <param name="pModulPath">cesta k suboru amod daneho modulu</param>
    ''' <param name="pUnit">nazov unitu z ktoreho ideme generovat formular</param>
    ''' <remarks></remarks>
    Public Sub GenerateOneFormProject(ByVal pModul As String, ByVal pModulPath As String, ByVal pUnit As String)
        Dim codeHandler As CodeHandler

        codeHandler = New CodeHandler(aFileNames, Me.aPathRootTemplate, Me.aPathDestination, Me.aProjectName, Me.aSolutionName)
        If (codeHandler.existSolution()) Then ' ak existuje solution
            If (codeHandler.existForm(pModul, pUnit)) Then ' ak uz existuje formular
                ' ak existuje uz formular opytam sa ci ho mam prepisat alebo nie
                Dim reply As DialogResult = MessageBox.Show("Formulár '" + aFileNames.mPrefixFrm + pUnit + "' už existuje. Chcete ho nahradiť?", "Generovanie Formuláru", _
                  MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

                If reply = DialogResult.Yes Then
                    ' vytvorim fomrular a nahradim
                    GenerateOneFormular(pModul, pModulPath, pUnit, True)
                End If
            Else
                'vytvorim formular
                Dim aPathDestModul As String
                aPathDestModul = Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFolderModules & "\" & pModul
                Dim aUnits As New List(Of String)
                aUnits.Add(pUnit)
                GenerateOneFormular(pModul, pModulPath, pUnit, False)
                Me.aSolutionWorker.addFiles(Me.aPathRootTemplate & "\" & Me.aFileNames.mFolderSolutionFileTemplates, aPathDestModul, aUnits, Me.getUnitRegVw(pModul), Me.getUnitReg(aUnits), pModul)
                Dim lUnit As New List(Of String)
                lUnit.Add(pUnit)
                Me.aSolutionWorker.updateModFile(pModul, Me.getUnitReg(lUnit))
            End If
        Else ' ak neexistuje ziaden projekt
            Dim lModulsDict As Dictionary(Of String, String) = New Dictionary(Of String, String)
            lModulsDict.Add(pModul, pModulPath)
            GenerateProject(lModulsDict, pUnit)
        End If
    End Sub
#End Region



#Region "Generate Complet New Project"
    ''' <summary>
    ''' Spusti vytvaranie celeho projektu
    ''' </summary>
    ''' <param name="lModulesDict">Slovnik nazov modulu a cesta k amodu</param>
    ''' <remarks></remarks>
    Public Sub GenerateProject(ByVal lModulesDict As Dictionary(Of String, String), ByVal pUnit As String)

        Dim aOnlyForUnit As Boolean = False
        If (pUnit.Length > 0) Then
            aOnlyForUnit = True
        End If


        Dim axmodFilePath As String = ""
        Dim aOtherFiles As New List(Of String)()
        Dim aResxFiles As New Dictionary(Of String, String)
        Dim aVBFiles As New List(Of String)()

        'temporary

        Dim lComponentsInit As String = ""
        Dim lComponentsSetting As String = ""
        Dim lComponentsAdd As String = ""
        Dim lComponentsFriend As String = ""
        Dim lComponentClickCode As String = ""


        Dim x As Integer = 50
        Dim y As Integer = 50
        'temporary end





        ' vyskoci okno kde si nastavim cestu k kroslib projekte
        Dim aOfd As New OpenFileDialog()
        aOfd.Filter = "VB Project Files (*.vbproj)|*.vbproj"
        aOfd.FileName = "D:\skola\Projekt\KrosLib\actual\SourceCode\KrosLib\KrosLib.vbproj"
        If (aOfd.ShowDialog() = DialogResult.OK) Then
            Me.aPathKroslibProject = aOfd.FileName
        End If

        ' nacitat settings pre DB Generator
        Dim aDlgDBGen As New DlgDBGenerator()
        If (Me.DBGeneratorSettings IsNot Nothing) Then    ' ak eksistuje uz nastavenie
            aDlgDBGen.SetComponents(Me.DBGeneratorSettings)
        End If
        aDlgDBGen.giveData(Me) ' prerobit na konstruktor a aby vracal denSettings ako navrat hodnotu
        aDlgDBGen.ShowDialog()

        Dim lPathAmodFilesForModuls As String = Me.aPathDestination

        Me.aModulesDict = New Dictionary(Of String, String)
        Me.aModulesDict = lModulesDict

        ' 1 krok - skopirovanie solution template na cielove miesto
        Me.aSolutionWorker.createSolution()

        ' 2 krok - vygenerovanie databazy na disk na urcene miesto

        If (Me.DBGeneratorSettings.areSettingsCorrect() = False) Then

            MessageBox.Show("Nenastavili ste nastavenia pre Databázový generátor. Z tohto dôvodu nebude vygenerovana Databáza.")
        Else
            Me.DBGenerator.generateWholeDatabaseScript(Me.aDbGenSettings, Me.aModulesDict)
            SQL_worker.createDB(Me.aDbGenSettings.DbName, Me.DBGenerator.ScriptDatabaseCreate, Me.DBGenerator.ScriptTablesCreate, Me.DBGenerator.ScriptSystem, Me.DBGeneratorSettings.ServerName)

        End If


        For Each lOneModule As KeyValuePair(Of String, String) In Me.aModulesDict





            y = 50

            Dim aDat As Dat       ' dat vytvoreni nacitanim jednoho aMod suboru
            Dim aOneDataset As DsAModOneVersion ' dataset jednej verzie z ktoreho sa bude generovat databaza
            Dim aVersion As String
            Dim aPathDestModul As String
            aDat = New Dat("NazovModulu", "NazovModulu", "NazovModulu")

            ' 3 krok - pridanie formularov do adresarov modulov v novom projekte
            Dim aPathTemplateComponents As String = Me.aPathRootTemplate & "\" & Me.aFileNames.mFolderFormTemplates & "\" & Me.aFileNames.mFileFormComponents
            aDat.LoadDsComponents(aPathTemplateComponents)

            Me.aFrmGen = New GeneratorFormularov(Path.Combine(Me.aPathRootTemplate, Me.aFileNames.mFolderFormTemplates), aDat)
            aDat.LoadAMod(lOneModule.Value, "CHYBA - Nepodarilo sa otvoriť Amod súbor pri generovaní databázy.")

            ' nastavi sa verzia a nacita konkretny dataset podla verzie
            If (Me.aDbGenSettings.Ver = -1) Then
                aVersion = aDat.GetLastVersion.ToString()
                aOneDataset = aDat.GetVersionDataset(aVersion) 'ak ide o poslednu verziu
            Else
                aVersion = Me.aDbGenSettings.Ver
                aOneDataset = aDat.GetVersionDataset(aVersion)
            End If

            aDat.AddMainView(aVersion) ' vytvorenie pohladu
            aDat.SaveAMod(aPathDestination & "\" & aProjectName & "\" & aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & lOneModule.Key & aFileNames.mExtensionAmod, "Chyba - Nepodarilo sa ulozit Amod subor.")
            Dim aUnits As New List(Of String)
            Dim i As Integer = 0
            For Each aDataRow As DataRow In aOneDataset.Tables(aOneDataset.UnitsTable.TableName).Rows
                Dim aUnitName As String = (aDataRow("UnitName"))  'dano
                If (((aOnlyForUnit = True) And (pUnit = aUnitName)) Or (aOnlyForUnit = False)) Then
                    aUnits.Add(aUnitName)
                    Dim aFrmFormulareExport As FrmFormulareExport = New FrmFormulareExport(Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFolderModules & "\" & lOneModule.Key, aUnitName, aFrmGen, aExportSettings, aDat.GetLastVersion, "Zoznamovy Form")
                    aFrmFormulareExport.ShowDialog()
                    i += 1

                    'temporary
                    ' budem lepit zdrojaky pre buttony aby som dokazal z hlavneho formularu otvorit vsetky formulare
                    Dim lName As String = lOneModule.Key & "_" & aUnitName
                    lComponentsInit += Me.GetComponentInitsCode(lName)

                    lComponentsSetting += Me.GetComponenttSettingsCode(lName, x, y)

                    lComponentsAdd += Me.GetComponentAddsCode(lName)

                    lComponentsFriend += Me.GetComponentFriendsCode(lName)

                    lComponentClickCode += Me.GetComponentClicksCode(lName, aUnitName)

                    'temporary koniec
                    y += 50

                    aResxFiles.Add(aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionVBSource, aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionResx)
                    aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixFrm & aUnitName & aFileNames.mExtensionVBSource)
                    aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixLog & aUnitName & aFileNames.mExtensionVBSource)
                End If
            Next



            aPathDestModul = Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFolderModules & "\" & lOneModule.Key

            ' 4 krok - pridanie log,mod,dat suborov do adresarov modulov v novom projekte dano
            Me.aSolutionWorker.addFiles(Me.aPathRootTemplate & "\" & Me.aFileNames.mFolderSolutionFileTemplates, aPathDestModul, aUnits, Me.getUnitRegVw(lOneModule.Key), Me.getUnitReg(aUnits), lOneModule.Key)

            ' 5 krok - zhromazdenie vsetkcych suborov na ktore sa natiahnu referencie
            axmodFilePath = aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & Me.aFileNames.mPrefixMod & lOneModule.Key & Me.aFileNames.mExtensionXmod

            ' 6 krok - pridanie referencii

            ' xmod a amod
            aOtherFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & lOneModule.Key & Me.aFileNames.mExtensionAmod)
            aOtherFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & Me.aFileNames.mPrefixMod & lOneModule.Key & Me.aFileNames.mExtensionXmod)

            ' mod dat log subory
            aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixDat & lOneModule.Key & aFileNames.mExtensionVBSource)
            aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixMod & lOneModule.Key & aFileNames.mExtensionVBSource)
            aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixLog & lOneModule.Key & aFileNames.mExtensionVBSource)

            ' formular zoznamovy
            aResxFiles.Add(aFileNames.mPrefixFrm & lOneModule.Key & aFileNames.mExtensionVBSource, aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixFrm & lOneModule.Key & aFileNames.mExtensionResx)
            aVBFiles.Add(aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixFrm & lOneModule.Key & aFileNames.mExtensionVBSource)


            aDat.ExportToXMod(aVersion, aPathDestination & "\" & aProjectName & "\" & aFileNames.mFolderModules & "\" & lOneModule.Key & "\" & aFileNames.mPrefixMod & lOneModule.Key & aFileNames.mExtensionXmod)
            x += 100 ' temporary


            aFrmGen.ExportujZoznamovyFormular("Zoznamovy Form", Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFolderModules & "\" & lOneModule.Key, aExportSettings, aDat.GetLastVersion, aFileNames.mPrefixFrm & lOneModule.Key)
        Next


        ' 7 krok - uprava inicializacneho suboru init

        Me.aSolutionWorker.updateInitFile(Me.aPathDestination & "\" & Me.aProjectName, Me.aDbGenSettings.ServerName, Me.aDbGenSettings.DbPath & "\" & Me.aDbGenSettings.DBFileName & Me.aFileNames.mExtensionDbSql, "", "", aModulesDict.Keys.ToArray)




        Me.aSolutionWorker.updateSolutionFile(Me.aPathDestination, Me.aPathKroslibProject, Me.aProjectName & "\" & Me.aFileNames.mFileTplProjectFile)
        'temporary
        Me.aSolutionWorker.updateMainForm(Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFileTplFrmMain, Me.aPathDestination & "\" & Me.aProjectName & "\" & Me.aFileNames.mFileTplFrmMainDesigner, lComponentsInit, lComponentsSetting, lComponentsAdd, lComponentsFriend, lComponentClickCode)
        'temporary finish

        ' 8 krok - uprava projektoveho suboro pridanie referencii na subory vb, xmod, amod, log, dat, mod

        Me.aSolutionWorker.updateProjectFile(aPathDestination & "\" & aProjectName, aOtherFiles, aResxFiles, aVBFiles)


    End Sub
#End Region







#Region "Metody pre simulaciu generovania"

    ''' <summary>
    ''' Metoda vrati list objektov Dat, kazdy modul je predstavovany jednym objektom typu Dat
    ''' </summary>
    ''' <param name="pSolutionAmod">Dataset z ktoreho sa vytvori list Amodov typu Dat</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getModulesForGenerating(ByVal pSolutionAmod As DsAmodSolution) As Dictionary(Of String, String)
        Dim aModulesDict As Dictionary(Of String, String) = New Dictionary(Of String, String)
        ' Me.mSolutionName = pSolutionAmod.ModulesDS(0).SolutionName  ' nastavim si meno ' dano
        ' prechadzanie datasetu a vytvorenie slovnka kde bude meno modulu a cesta k amod suboru
        For Each aModulDataRow As DataRow In pSolutionAmod.Modules
            aModulesDict.Add(aModulDataRow("ModuleName").ToString(), Path.Combine(Me.aPathDestination, aModulDataRow("RelativePath").ToString()))
        Next
        Return aModulesDict
    End Function
    ''' <summary>
    ''' Metoda pre simulaciu gnerovaia
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    Public Sub initDataForSimulation()
        Dim DlgDBGen As New DlgDBGenerator()
        If (Me.DBGeneratorSettings IsNot Nothing) Then    ' ak eksistuje uz nastavenie
            DlgDBGen.SetComponents(Me.DBGeneratorSettings)
        End If
        DlgDBGen.giveData(Me) ' prerobit na konstruktor a aby vracal denSettings ako navrat hodnotu
        DlgDBGen.ShowDialog()

        'Me.mPathDestination = "E:\templateWorks\destination"
        'Me.mPathRootTemplate = "E:\templateWorks\Templates"
        'Me.mSolutionName = "NewTestProject"


    End Sub
#End Region
End Class
